package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.DataClassification;
import com.zygh.interactiveplatform.module.service.DataClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-02-03
 */
@RestController
@RequestMapping("/data-classification")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_DATA_CLASSIFICATION})
public class DataClassificationController {
    @Resource
    private DataClassificationService dataClassificationService;

    @ApiOperation(value = "数据分类新增", notes = "数据分类新增")
    @PostMapping("addDataClassificatione")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_DATA_CLASSIFICATION, content = "数据分类新增")
    public ResponseDTO addDataClassificatione(@RequestBody @Valid DataClassification dataClassification) {
        return dataClassificationService.addDataClassification(dataClassification);
    }

    @ApiOperation(value = "数据分类修改", notes = "数据分类修改")
    @PostMapping("updateDataClassification")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_DATA_CLASSIFICATION, content = "数据分类修改")
    public ResponseDTO updateDataClassification(@RequestBody @Valid DataClassification dataClassification) {
        return dataClassificationService.updateDataClassification(dataClassification);
    }

    @ApiOperation(value = "数据分类删除", notes = "数据分类删除")
    @PostMapping("deleteDataClassification")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_DATA_CLASSIFICATION, content = "数据分类删除")
    public ResponseDTO deleteDataClassification(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return dataClassificationService.deleteDataClassification(new_id);
    }

    @ApiOperation(value = "查询所有数据分类", notes = "查询所有数据分类")
    @GetMapping("findDataClassificationAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_DATA_CLASSIFICATION, content = "查询所有数据分类")
    public ResponseDTO findDataClassificationAll(Integer current, Integer size) {
        return dataClassificationService.findDataClassificationAll(current, size);
    }
}
